Public Class Form1 Private Function ExtractLine(ByVal text As String, ByRef line As String, ByRef startPos As Integer, ByRef foundPos As Integer) As Boolean ' find the next occurrence of the new line char foundPos = text.IndexOf(ControlChars.NewLine, startPos) ' check if it was found If foundPos = -1 Then Return False Else ' pull out the current line of the file line = text.Substring(startPos, foundPos - startPos) ' update the starting point for search startPos = foundPos + 2 Return True End If End Function Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim allText As String Dim lineExists As Boolean Dim currentDVD As String Dim start As Integer = 0 Dim foundPos As Integer ' check if file exists If My.Computer.FileSystem.FileExists("DVDs.txt") Then ' read the file contents allText = My.Computer.FileSystem.ReadAllText("DVDs.txt") ' while not at end, extract line Do lineExists = ExtractLine(allText, currentDVD, start, foundPos) If lineExists Then ' stick the line in the list box lstChoice.Items.Add(currentDVD) End If Loop While lineExists Else MsgBox("Please put the DVDs.txt file in the bin folder for the project") End If End Sub Private Sub lstChoice_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstChoice.SelectedIndexChanged Dim choice As String choice = lstChoice.SelectedItem().ToString() Dim movie As String Dim priceStr As String Dim commaPos As Integer commaPos = choice.IndexOf(",") movie = choice.Substring(0, commaPos) txtTitle.Text = movie priceStr = choice.Substring(commaPos + 2) txtPrice.Text = priceStr Dim tax As Double Dim price As Double Dim total As Double Dim isConverted As Boolean isConverted = Double.TryParse(priceStr, price) tax = price * 0.07 total = price + tax txtTax.Text = tax.ToString("c") txtTotal.Text = total.ToString("c") End Sub Private Sub btnPay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPay.Click If txtTitle.Text <> "" Then My.Computer.FileSystem.WriteAllText("sales.txt", txtTitle.Text & _ "," & txtPrice.Text & "," & txtTax.Text & "," & _ txtTotal.Text & ControlChars.NewLine, True) End If End Sub End Class